/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author TAKUYA
 */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Compare2 {
	public static void main(String[] args)
	{
	Compare2 compare = new Compare2();

	double x1 = compare.read1(1);
	double y1 = compare.read1(2);
	double z1 = compare.read1(3);
        double x2 = compare.read2(1);
	double y2 = compare.read2(2);
	double z2 = compare.read2(3);



	String outputSt = compare.judge(x1, y1, z1, x2, y2, z2);

	compare.write(outputSt);
	}



	public double read1(int number) {
        BufferedReader br = null;
        try {
            File inputfile = new File("C:/textdata/input1.txt");
            if (checkBeforeReadfile(inputfile)){


            br = new BufferedReader(new FileReader(inputfile));
            String line;
            while ((line = br.readLine()) != null) {
            	String[] data = line.split("\t");
            	double x = Double.valueOf(data[0]);
                double y = Double.valueOf(data[1]);
                double z = Double.valueOf(data[2]);

               if (number == 1){
                   return x;
               }else if(number == 2){
                   return y;
               }else{
                   return z;
               }
            }
            }else{
            	System.out.println("Can't find or open");
            }

        } catch (IOException e) {
            e.printStackTrace();

        } finally {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
		return 0;

    }
        public double read2(int number) {
        BufferedReader br = null;
        try {
            File inputfile = new File("C:/textdata/input2.txt");
            if (checkBeforeReadfile(inputfile)){


            br = new BufferedReader(new FileReader(inputfile));
            String line;
            while ((line = br.readLine()) != null) {
            	String[] data = line.split("\t");
            	double x = Double.valueOf(data[0]);
                double y = Double.valueOf(data[1]);
                double z = Double.valueOf(data[2]);

               if (number == 1){
                   return x;
               }else if(number == 2){
                   return y;
               }else{
                   return z;
               }
            }
            }else{
            	System.out.println("Can't find or open");
            }

        } catch (IOException e) {
            e.printStackTrace();

        } finally {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
		return 0;

    }
	
	 private static boolean checkBeforeReadfile(File file){
		    if (file.exists()){
		      if (file.isFile() && file.canRead()){
		        return true;
		      }
		    }

		    return false;
		  }

	 public String judge(double x1, double y1, double z1, double x2, double y2, double z2){
		 double setx = 2.0;
		 double sety = 3.0;
		 double setz = 4.0;
		 double norm = Math.sqrt(Math.pow(x1 - setx, 2) + Math.pow(y1 - sety, 2) + Math.pow(z1 - setz, 2));
		 double lim = 3.0;
                 double N1 = Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2) + Math.pow(z1, 2));
                 double N2 = Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2) + Math.pow(z2, 2));

                 String dx = Double.toString(x1 - setx);
		 String dy = Double.toString(y1 - sety);
		 String dz = Double.toString(z1 - setz);
		 String normSt = Double.toString(norm);
		 String crlf = System.getProperty("line.separator");

		 if (norm < lim){
			 boolean posturejudge = true;
                         String posturejudgeSt = Boolean.toString(posturejudge);
                         String outputSt = (posturejudgeSt + crlf + "dx = "  + dx + crlf + "dy = " + dy + crlf + "dz = " + dz + crlf + "norm = " + normSt);

                         return outputSt;

                 }else if(norm > lim && N2*0.95 < N1 && N2*1.05 > N1){

                         boolean posturejudge = true;
                         String posturejudgeSt = Boolean.toString(posturejudge);
			 String outputSt = (posturejudgeSt + crlf + "dx = "  + dx + crlf + "dy = " + dy + crlf + "dz = " + dz + crlf + "norm = " + normSt);

                         return outputSt;

                 }else{
                         boolean posturejudge = false;
                         String posturejudgeSt = Boolean.toString(posturejudge);
			 String outputSt = (posturejudgeSt + crlf + "dx = "  + dx + crlf + "dy = " + dy + crlf + "dz = " + dz + crlf + "norm = " + normSt);

			 return outputSt;
		 }
	 }

	 public void write(String outputSt){
		    try{
		      File outputfile = new File("C:/textdata/output.txt");

		      if (checkBeforeWritefile(outputfile)){
		        FileWriter filewriter = new FileWriter(outputfile);
		        filewriter.write(outputSt);

		        filewriter.close();
		      }else{
		        System.out.println("Can't write");
		      }
		    }catch(IOException e){
		      System.out.println(e);
		    }
		  }

		  private static boolean checkBeforeWritefile(File file){
		    if (file.exists()){
		      if (file.isFile() && file.canWrite()){
		        return true;
		      }
		    }

		    return false;
		  }


}
